package com.sec.android.app.myfiles.module.shortcut;

import android.content.Context;

import com.sec.android.app.myfiles.facade.FacadeItem;
import com.sec.android.app.myfiles.fragment.AbsMyFilesFragment;
import com.sec.android.app.myfiles.fragment.home.HomeFragment;
import com.sec.android.app.myfiles.fragment.home.HomeFragmentItem;
import com.sec.android.app.myfiles.info.MediaFile;
import com.sec.android.app.myfiles.module.ContentObservable;
import com.sec.android.app.myfiles.module.abstraction.AbsContentObserverImp;
import com.sec.android.app.myfiles.module.abstraction.AbsDragAndDrop;
import com.sec.android.app.myfiles.module.abstraction.AbsFileListAdapterImp;
import com.sec.android.app.myfiles.module.abstraction.AbsFileOperationImp;
import com.sec.android.app.myfiles.module.abstraction.AbsMenuImp;
import com.sec.android.app.myfiles.module.abstraction.AbsModuleLoaderImp;
import com.sec.android.app.myfiles.module.abstraction.AbsProviderImp;
import com.sec.android.app.myfiles.module.abstraction.AbsReloadStrategyImp;
import com.sec.android.app.myfiles.module.abstraction.FileRecord;
import com.sec.android.app.myfiles.module.abstraction.FileRecord.StorageType;
import com.sec.android.app.myfiles.module.shortcut.cmd.AddShortcutCmd;
import com.sec.android.app.myfiles.navigation.NavigationInfo;
import com.sec.android.app.myfiles.operation.ProgressListener;
import com.sec.android.app.myfiles.provider.DbTableInfo;
import com.sec.android.app.myfiles.widget.listview.AbsListViewImp;

import java.util.ArrayList;

public class ShortcutModuleLoaderImp extends AbsModuleLoaderImp {
    @Override
    protected FileRecord _createFileRecord(String fullPath) {
        return new ShortcutFileRecord(fullPath, FileRecord.getName(fullPath), MediaFile.getFileType(fullPath));
    }

    @Override
    protected FileRecord _createFileRecord(int id, String path, String name, long size, long date, int fileType, int isHidden, int itemCount,
                                           int itemCountHidden) {
        return new ShortcutFileRecord(path, name, fileType);
    }

    @Override
    protected AbsFileListAdapterImp _createAdapterImp(Context context, NavigationInfo navigationInfo, AbsListViewImp listView) {
        return new ShortcutAdapterImp(context, navigationInfo, listView.getItemLayoutId(), null, 0);
    }

    @Override
    protected AbsProviderImp _createProviderImp(Context context) {
        return new ShortcutProviderImp(context);
    }

    @Override
    protected DbTableInfo _getTableInfoImp() {
        return ShortcutDbTableInfo.getInstance();
    }

    @Override
    protected AbsMenuImp _createMenuImp(Context context, StorageType supportStorage) {
        return new ShortcutMenuImp(context, supportStorage);
    }

    @Override
    protected AbsFileOperationImp _createFileOperationImp(Context context, ProgressListener listener) {
        return new ShortcutOperationImp(context, listener);
    }

    @Override
    protected void _createHomeItem(Context context, HomeFragment fragment, ArrayList<HomeFragmentItem> itemList, boolean isLeftPanel) {
        if (fragment != null) {
            NavigationInfo info = fragment.getNavigationInfo();
            if (info != null && info.getNavigationMode() != NavigationInfo.NavigationMode.Select_optimize_storage_backup_destination && !info.isPickerMode()) {
                HomeFragmentItem shortcut = new ShortcutHomeItem(context, fragment);
                itemList.add(shortcut);
            }
        }
    }

    @Override
    protected void _addFacadeItemList(ArrayList<FacadeItem> facadeItem) {
        facadeItem.add(FacadeItem.createFacadeItem(FacadeItem.ADD_SHORTCUT, new AddShortcutCmd()));
        facadeItem.add(FacadeItem.createFacadeItem(FacadeItem.MANAGE_SHORTCUT, new ManageShortcutCmd()));
    }

    @Override
    protected AbsContentObserverImp _createContentObserver(Context context, FileRecord record, ContentObservable updater) {
        //Do nothing in shortcut
        return null;
    }

    @Override
    protected AbsReloadStrategyImp _createReloadStrategy(Context context, NavigationInfo navigationInfo) {
        //Do nothing in shortcut
        return null;
    }

    @Override
    protected FileRecord.StorageType getSupportStorage() {
        return FileRecord.StorageType.Shortcut;
    }

    @Override
    protected AbsDragAndDrop _getDragAndDropImp(AbsMyFilesFragment fragment, AbsListViewImp listViewImp) {
        return new ShortcutDragAndDropImp(fragment, listViewImp);
    }
}
